package library.operation.impl;

import library.book.Book;
import library.book.BookList;
import library.operation.IOperation;

/**
 * 增加书籍操作
 */
public class AddOperation implements IOperation {
    @Override
        //假设此时书架上已经有这本书了~~
        public void work(BookList bookList) {
            System.out.println("此时您进行的是添加书籍操作~");
            System.out.println("请输入您要添加的书籍名称：");
            String booksName=scanner.nextLine();
        //对于书本类来说，书名这个属性时唯一的，就相当于书架上的“索引”
        if (bookList.contains(booksName)){
            System.err.println(booksName+"在当前书架上已经存在了，无需重复添加~");
            return;
        }
        System.out.println("请输入您要添加书籍的作者:");
        String author=scanner.nextLine();
        System.out.println("请输入您要添加书籍的类别:");
        String type=scanner.nextLine();
        System.out.println("请输入您要添加书籍的价格:");
        double price=scanner.nextDouble();
        scanner.nextLine();
        //产生书籍对象，保存在书架上
        bookList.addNewBook(booksName,author,type,price);
        System.out.println("添加书籍成功~~~");
    }
}
